package com.xt.core.service.hibernate;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

import org.appfuse.service.impl.GenericManagerImpl;

import com.xt.core.service.BasicService;
import com.xt.core.dao.BasicDao;
import com.xt.core.data.BasicDBObject;
import com.xt.core.exception.ObjectCanNotSaveException;
import com.xt.core.helper.page.Pager;


/**
 * Generic Manager in hibernate implementaion that talks to BasicDao to CRUD POJOs.
 *
 * <p>Extend this interface if you want typesafe (no casting necessary) managers
 * for your domain objects.
 *
 * <p>Extended the GenericManagerImpl from appfuse framework
 * 
 * @author txiao
 * @version Revision: 1.0, Date: 23.09.2009
 * @param <T> a type variable
 * @param <PK> the primary key for that type
 */
public class BasicServiceImpl<T, PK extends Serializable> 
	extends GenericManagerImpl<T, PK> 
	implements BasicService<T, PK>{
	
	protected BasicDao<T, PK> basicDao;
	
	public BasicServiceImpl(BasicDao<T, PK> basicDao) {
		super(basicDao);
		this.basicDao = basicDao;
	}
	
	/*
     * Add your function here
     */
	public void saveorupdate(T object) throws ObjectCanNotSaveException{
		basicDao.saveorupdate(object);
	}
	
	public int getTotalRows(){
		return basicDao.getTotalRows();
	}
	
	public int getTotalRows(Set<LinkedHashMap<String, Object>> queryParams){
		return basicDao.getTotalRows(queryParams);
	}
	
	public long getTotalRows(String queryString){
		return basicDao.getTotalRows(queryString);
	}
	
	public List<T> getAll(Set<LinkedHashMap<String, Object>> queryParams, LinkedHashMap<String, String> order){
		return basicDao.getAll(queryParams, order);
	}
	
	public List<T> getOnePage(int pageSize, int startRow){
		return basicDao.getOnePage(pageSize, startRow);
	}
	
	public List<T> getOnePage(Pager pager){
		return basicDao.getOnePage(pager);
	}
	
	public List<T> getOnePage(int pageSize, int startRow, Set<LinkedHashMap<String, Object>> queryParams, LinkedHashMap<String, String> order){
		return basicDao.getOnePage(pageSize, startRow, queryParams, order);
	}
	
	public List<T> getOnePage(Pager pager, Set<LinkedHashMap<String, Object>> queryParams, LinkedHashMap<String, String> order){
		return basicDao.getOnePage(pager,queryParams,order);
	}
	
	public List<T> getOnePage( String queryString, int pageSize, int startRow){
		return basicDao.getOnePage(queryString, pageSize, startRow);
	}
	
	public List<T> getOnePage( String queryString, Pager pager){
		return basicDao.getOnePage(queryString, pager);
	}
}
